#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cstring>
#define endl "\n"
using namespace std;
int bp[1005][1005],a[1005][1005],n;
int f(int x,int y)
{
	if (bp[x][y] != 0)
		return bp[x][y];
	if (x == n-1)
	{
		return bp[x][y] = a[x][y] + max(a[x + 1][y], a[x + 1][y + 1]);
	}
	else
		return  bp[x][y]=max(f(x + 1, y)+a[x+1][y], f(x + 1, y + 1)+a[x+1][y+1]);
}
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= i; j++)
		{
			cin >> a[i][j];
		}
	}
	cout<<f(1, 1);
	return 0;
}